package com.nightsoul.ehcache.test;

import java.net.URL;

import org.ehcache.Cache;
import org.ehcache.CacheManager;
import org.ehcache.config.builders.CacheConfigurationBuilder;
import org.ehcache.config.builders.CacheManagerBuilder;
import org.ehcache.config.builders.ResourcePoolsBuilder;


public class XmlConfiguration {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		URL url = XmlConfiguration.class.getResource("/ehcache.xml");
		org.ehcache.xml.XmlConfiguration xmlConfiguration = new org.ehcache.xml.XmlConfiguration(url);
		
		CacheConfigurationBuilder<String, Object> configurationBuilder = xmlConfiguration.newCacheConfigurationBuilderFromTemplate("example", String.class, Object.class);
		configurationBuilder = configurationBuilder.withResourcePools(ResourcePoolsBuilder.heap(1000));
		
		
		CacheManager cacheManager = CacheManagerBuilder.newCacheManager(xmlConfiguration);
		cacheManager.init();
		
		Cache<String, Object> cache = cacheManager.getCache("firstCache", String.class, Object.class);
		cache.put("name", "zhangsan");
		System.out.println(cache.get("name"));
		
		Cache<String, Object> secondCache = cacheManager.createCache("secondCache", configurationBuilder);
		System.out.println(secondCache);
		
		cacheManager.close();
	}

}
